package leetcom.ncom49;

public class Ex5706 {
    static class Solution {
        public boolean areSentencesSimilar(String sentence1, String sentence2) {
            String[] a ;
            String[] b ;

            if(sentence1.length()>sentence2.length()){
                a = sentence1.split(" ");
                b = sentence2.split(" ");
            }else{
                b = sentence1.split(" ");
                a = sentence2.split(" ");
            }

            int l1 = 0;
            int l2 = b.length-1;
            for(int i = 0;i<a.length;i++){
                if(l1<b.length&&a[i].equals(b[l1])){
                    l1++;
                }else{
                    break;
                }
            }
            for(int i = a.length-1;i>=0;i--){
                if(l2>=0&&a[i].equals(b[l2])){
                    l2--;
                }else{
                    break;
                }
            }
            if(l1>=l2){
                return true;

            }else{
                return false;
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        boolean b = solution.areSentencesSimilar("of", "A lot of words");
        System.out.println(b);
    }
}
